﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanLyThuVien.DAO
{
    class NhaSanXuatDAO
    {
        public static IEnumerable<NhaSanXuat> GetAllNSX()
        {
            NorthwindDataContext context = new NorthwindDataContext();
            IEnumerable<NhaSanXuat> sql = from NSX in context.NhaSanXuats select NSX;
            return sql;
        }

        public static DataGridView GetAllNSXuat()
        {
            NorthwindDataContext db = new NorthwindDataContext();
            DataGridView dt = new DataGridView();
            var sql = from NSX in db.NhaSanXuats select NSX;
            dt.DataSource = sql;
            return dt;
        }

        public static void Them(NhaSanXuat NSX)
        {
            NorthwindDataContext context = new NorthwindDataContext();
            NhaSanXuat a = new NhaSanXuat();
            a.TenNhaSanXuat = NSX.TenNhaSanXuat;
            context.NhaSanXuats.InsertOnSubmit(a);
            context.SubmitChanges();
        }


        public static void Sua(NhaSanXuat S)
        {

            NorthwindDataContext context = new NorthwindDataContext();
            NhaSanXuat a = context.NhaSanXuats.Single(snsx => snsx.MaNhaSanXuat == S.MaNhaSanXuat);
            a.TenNhaSanXuat = S.TenNhaSanXuat;
            context.SubmitChanges();
        }

        // kiem tra nha xuat ban
        public static int KT_NhaXuatBan(string ten)
        {
            NorthwindDataContext db = new NorthwindDataContext();
            var ds = from nxb in db.NhaSanXuats
                     where nxb.TenNhaSanXuat == ten
                     select nxb;
            if (ds.Count() > 0)
            {
                return 1;
            }
            return 0;
        }
    }
}
